public class Shot implements Runnable{
    int x;// 子弹横坐标
    int y;// 子弹纵坐标
    int direct;// 方向
    int sleep = 2;// 速度
    boolean isLive = true;// 子弹是否存活

    public Shot(int x, int y, int direct) {
        this.x = x;
        this.y = y;
        this.direct = direct;
    }

    @Override
    public void run() {
        while (true){
            try {
                Thread.sleep(50);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            switch (direct){
                case 0:
                    y -= sleep;
                    break;
                case 1:
                    x += sleep;
                    break;
                case 2:
                    y += sleep;
                    break;
                case 3:
                    x -= sleep;
                    break;
            }
            // 当子弹碰到敌人坦克或者边界时.退出
            if (!(x >= 0 && x <= 1000 && y >= 0 && y <= 750 && isLive)){
                isLive = false;
                break;
            }
        }
    }
}
